<template>
    <div>
        <Table :columns="columns" :data="chapterList"></Table>
    </div>
</template>
<script>
import ChapterAPI from '@/api/knowledge/ChapterAPI';
export default {
    props: ['courseId'],
    mounted() {
        this.fetchChapterList();
    },
    data() {
        return {
            chapterList: [],
            columns: [
                {
                    title: '章节标题',
                    key: 'title',
                    width: 300
                },
                {
                    title: '章节描述',
                    key: 'description'
                },
                {
                  title: '视频格式',
                  key: 'materialType'
                },
                {
                  title: '浏览量',
                  key: 'views',
                  width: 100
                },/*,
                {
                    title: '操作',
                    key: 'action',
                    width: 150,
                    render: (h, params) => {
                        return h('div', [
                            h('Button', {
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                on: {
                                    click: () => {
                                        this.deleteChapter(params.row.id);
                                    }
                                }
                            }, '删除')
                        ]);
                    }
                }*/
            ]
        }
    },
    methods: {
        deleteChapter(chapterId) {
          alert(chapterId);
            let _this = this;
            ChapterAPI.deleteChapter(chapterId, function (resp) {
                _this.$Message.success("删除成功！");
                _this.fetchChapterList();
            }, function (error) {
                _this.$Message.error("操作失败【" + error + "】");
            })
        },
        fetchChapterList() {
            let _this = this;
            ChapterAPI.fetchChapterShowList(_this.courseId, function (resp) {
                _this.chapterList = resp;
            }, function (error) {
                _this.$Message.error("操作失败【" + error + "】");
            })
        }
    }
}
</script>
